package com.jinkaimen.kqb.ui.fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;

import com.ht.baselibs.core.EventCode;
import com.ht.baselibs.ui.base.BaseFragment;
import com.ht.baselibs.utils.AESUtils;
import com.ht.baselibs.utils.ActivityUtils;
import com.ht.baselibs.utils.AppAesUtil;
import com.ht.baselibs.utils.LogUtils;
import com.ht.baselibs.utils.SharedPreferencesUtils;
import com.jinkaimen.kqb.R;
import com.jinkaimen.kqb.ui.activity.LoginActivity;
import com.jinkaimen.kqb.ui.activity.ShareActivity;
import com.jinkaimen.kqb.ui.activity.TestWebViewActivity;
import com.jinkaimen.kqb.ui.activity.WebViewActivity;
import com.jinkaimen.kqb.ui.activity.addmerchant.RegisterActivity;
import com.jinkaimen.kqb.ui.activity.hss.CentralDocumentActivity;

import java.net.URLEncoder;

import static com.jinkaimen.kqb.constant.Constants.TOKEN;
import static com.jinkaimen.kqb.http.ConsultInterceptor.privateKey;


public class TextFragment extends BaseFragment {


    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected void initTitleBar() {

    }

    @Override
    protected View initContentView() {
        return LayoutInflater.from(mContext).inflate(R.layout.frag_home, null);
    }

    @Override
    protected void initChildView() {
        findViewById(R.id.bt_login).setOnClickListener(this);
        findViewById(R.id.bt_shop_in).setOnClickListener(this);
        findViewById(R.id.bt_central_document).setOnClickListener(this);
        findViewById(R.id.bt_regist).setOnClickListener(this);
        findViewById(R.id.bt_share_test).setOnClickListener(this);
        findViewById(R.id.text1).setOnClickListener(this);
        findViewById(R.id.text2).setOnClickListener(this);
//        findViewById(R.id.text01).setOnClickListener(this);

    }

    @Override
    protected void setChildViewListener() {

    }


    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.bt_login:
                ActivityUtils.startActivity(mContext, LoginActivity.class);
                break;
            case R.id.bt_shop_in:
                ActivityUtils.startActivity(mContext, TestWebViewActivity.class);

                break;
            case R.id.bt_central_document:
                ActivityUtils.startActivity(mContext, CentralDocumentActivity.class);

                break;
            case R.id.bt_regist:
                ActivityUtils.startActivity(mContext, RegisterActivity.class);

                try {
                    String encrypt = AESUtils.aesEncrypt("123456", "6w3W8OOgnRZrkBGS");
                    String aesDecrypt = AESUtils.aesDecrypt("uabjeGvCeElIZgbSzNtAcQ==", "6w3W8OOgnRZrkBGS");
                    //String encryptCBC_noPaddingToBase64String = AppAesUtil.encryptCBC_NoPaddingToBase64String("123456", "utf-8", "6w3W8OOgnRZrkBGS", "2AdpFTpOykcUsvfI");
///                   AESUtils.aesDecrypt()
                    String decryptCBC_noPaddingFromBase64String = AppAesUtil.decryptCBC_NoPaddingFromBase64String("Db7fC9PMTsr9CIGr7it1Lg==", "utf-8", privateKey.substring(0, 16), privateKey.substring(16, 32));

                    LogUtils.error("enctry-->:" + encrypt);
                    LogUtils.error("aesDecrypt-->:" + decryptCBC_noPaddingFromBase64String);

                } catch (Exception e) {
                    e.printStackTrace();
                }

                break;
            case R.id.bt_share_test:


                try {
                    String data = URLEncoder.encode(AppAesUtil.encryptCBC_NoPaddingToBase64String("123456"
                            , "utf-8", privateKey.substring(0, 16), privateKey.substring(16, 32)), "utf-8");

                    Log.e("ddddddddddddd", data);

                } catch (Exception e) {
                    e.printStackTrace();
                }

                ActivityUtils.startActivity(mContext, ShareActivity.class);

                break;
            case R.id.text1:
                Bundle bundle = new Bundle();
                String access_token = SharedPreferencesUtils.getString(TOKEN, "");
                bundle.putString(WebViewActivity.TITLE, "好收收");
                bundle.putString(WebViewActivity.URL, "http://192.168.1.134:8080/#/");
//                bundle.putString(WebViewActivity.URL, "file:///android_asset/demo.html");
//                + "?token=" + access_token
                bundle.putBoolean(WebViewActivity.LEFTIMAGE, false);
                ActivityUtils.startActivity(mContext, WebViewActivity.class, bundle);
                break;
            case R.id.text2:
                Bundle bundle1 = new Bundle();
                bundle1.putString(WebViewActivity.TITLE, "好收收");
                bundle1.putString(WebViewActivity.URL, "file:///android_asset/demo.html");
//                + "?token=" + access_token
                bundle1.putBoolean(WebViewActivity.LEFTIMAGE, false);
                ActivityUtils.startActivity(mContext, WebViewActivity.class);
                break;

        }
    }

    @Override
    protected boolean hasEvent() {
        return true;
    }

    @Override
    protected void onEvent(int eventCode, Object data) {
        super.onEvent(eventCode, data);
        switch (eventCode) {
            case EventCode.HSY_REQUEST_CODE_EXPIRE://登陆超时

                break;

        }
    }

    @Override
    public void onResume() {
        super.onResume();

    }
}
